#pragma once

namespace Tmpl {

#define MSG_ID_IRRELEVANT -1

struct MsgData
{
	enum MsgDataType
	{
		MSG_DEFAULT,

		MSG_SPAWN_PROJECTILE,
		MSG_SPAWN_UNIT,

		MSG_DAMAGE_DONE,
		MSG_BUILDING_PROGRESS,
	};

	struct MsgDefault
	{
		char type;
		int sender;
		int receiver;
		void* data;
	};

	struct MsgDamageDone
	{
		int sender;
		int receiver;
		float dmg;
	};

	struct MsgSpawnProjectile
	{
		int empireId;
		int ownerId;
		Vec2sf pos;
		Vec2sf facing;
		UnitData data;
	};

	char msgType;
	union
	{
		MsgDefault msgDefault;
		MsgDamageDone damageDone;
		MsgSpawnProjectile spawnProjectile;
	};
	
};

/*
class BaseMsgHandler
{
public:
	virtual void Exec(MsgData& data) = 0;
};
*/

class MessageSystem
{
public:
	static void Init();
	static void Clear();

	static void HandleAllMessages();
	static void ProcessMessage(const MsgData& msg);

	static void AddMsgSpawnProjectile(int empireId, int ownerId, Vec2f pos, Vec2f facing, UnitData& data, int creator=MSG_ID_IRRELEVANT);
	static void AddMsgDamageDone(int sender, int receiver, float damage, int creator=MSG_ID_IRRELEVANT);
	static void AddMsg(char msgType, int sender, int receiver, void* data, int creator=MSG_ID_IRRELEVANT);
};

} // namespace Tmpl